package 剑指offer;

import java.util.Arrays;

import org.junit.Test;

public class _59_1滑动窗口的最大值 {
	@Test
	public void test() {
		int []nums = {1,3,-1,-3,5,3,6,7};
		System.out.println(Arrays.toString(maxSlidingWindow(nums, 3)));
	}
	 public int[] maxSlidingWindow(int[] nums, int k) {
		 if(nums.length == 0) return nums;
		 int []res = new int[nums.length-k+1]; 
		 int left = 0,right = k-1; 
		  for (int i = 0; i < res.length; i++) {
			  int max = Integer.MIN_VALUE;
			for (int j = left; j <= right; j++) {
				if(max < nums[j]) max = nums[j];
			}
			res[i] = max;
			left++;
			right++;
		}
		 return res;
	    }
}
